home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Tele / C / Comet2.1.3 Folder / Comet / config.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-07  |  32.1 KB  |  1,362 lines  |  [TEXT/????]

  1. /*
  2.     Copyright Cornell University 1986.  All rights are reserved.
  3.     
  4.     routines to save and retrieve configuration info, such as Control
  5.     menu item state.
  6. */
  7.  
  8. #include <em.h>
  9.  
  10. #include <3270.h>
  11. #include <h19.h>
  12. #include <config.h>
  13. #include <macdefs.h>
  14. #include <resdefs.h>
  15. #include <util.h>
  16.  
  17. #define CONFID        0
  18.  
  19. #define VERS1         1
  20. #define VERS2         2
  21. #define VERS3         3
  22. #define VERS4         4
  23. #define VERS5         5
  24. #define VERS6         6
  25. #define VERS7         7
  26. #define VERS8         8
  27. #define VERS9         9
  28. #define VERS10         10
  29. #define VERS11         11
  30. #define VERS13         13
  31.  
  32. #define CURVERSION    VERS13                /* current config version number */
  33.  
  34. #define GLOBVERSION    4
  35.  
  36. #define VERS1KEYBOARD    11
  37. #define VERS1KEYPAD    14
  38.  
  39. #define NEG (-1)
  40.  
  41. SysEnvRec        environs;
  42.  
  43. short setresfid;
  44. short setresvref;            /* volume ref num for Default file */
  45. short setresvol;
  46. long setresdir;                /* "Comte Default" directory and volume */
  47.  
  48. char * strsetcantopen = "Can't open 'Comet Default'";
  49. char * strbadvol = "Can't change directories";
  50.  
  51. extern Handle modresource();
  52.  
  53.  
  54. /* get global configuration information */
  55.  
  56. globalconfig()
  57. {
  58.     Handle hsize;
  59.         
  60.     if ((hsize = GetResource('SIZE', (short) -1)) != NULL) {
  61.         /* check to see if we are intended to run in background */
  62.         if (**hsize & 0x04)
  63.             /* "background only" has been set */
  64.             mfbackonly = TRUE;
  65.         ReleaseResource(hsize);
  66.     }
  67.  
  68.     if (SysEnvirons(1, &environs)) {
  69.         /* error("Your System is out of date!");    
  70.             too obtrusive! 512KE can't run the right system anyway... */
  71.             
  72.         keyboard = OLDKEYBOARD;
  73.  
  74.     }
  75.     else {
  76.         if (environs.keyBoardType == envUnknownKbd 
  77.                 || environs.keyBoardType == envMacKbd 
  78.                 || environs.keyBoardType == envMacAndPad)
  79.             keyboard = OLDKEYBOARD;
  80.         else
  81.             keyboard = PLUSKEYBOARD;
  82.     }
  83.  
  84. }
  85.  
  86. /* get the emulator configuration from the CONF resource */
  87.  
  88. getconfig()
  89. {
  90.     Handle hconfig;
  91.     struct config * confp;
  92.     Handle sizeh;
  93.  
  94.     sizeh = GetResource('Fsiz', (short) 0);
  95.     if (sizeh != NULL) {
  96.         emdp->fontsize = *((short *) *sizeh);
  97.         ReleaseResource(sizeh);
  98.     }
  99.     else
  100.         emdp->fontsize = 0;                /* will use default font */
  101.  
  102.     /* get connect macro resource */
  103.     emdp->connmacro = Get1Resource('CONN', 0);
  104.     if (emdp->connmacro != NULL)
  105.         DetachResource(emdp->connmacro);
  106.  
  107.     /* get close macro resource */
  108.     emdp->closemacro = Get1Resource('CONN', 1);
  109.     if (emdp->closemacro != NULL)
  110.         DetachResource(emdp->closemacro);
  111.  
  112.     /* get double-click macro resource */
  113.     emdp->clickmacro = GetResource('CLIK', 0);
  114.     if (emdp->clickmacro != NULL)
  115.         DetachResource(emdp->clickmacro);
  116.  
  117.     /* get TCP host address resource */
  118.     emdp->hlasthost = Get1Resource('LHST', 0);
  119.     if (emdp->hlasthost != NULL)
  120.         DetachResource(emdp->hlasthost);
  121.     
  122.     defaultconf();
  123.     if ((hconfig = GetResource('CONF', (short) CONFID)) == NULL) {
  124.         /* default configuration */
  125.         return(-1);
  126.     }
  127.  
  128.     HLock(hconfig);
  129.     confp = (struct config *) *hconfig; 
  130.  
  131.     if (confp->version_number < VERS1) {
  132.         /* do default configuration */
  133.         error("Your document is damaged, using default");
  134.         HUnlock(hconfig);
  135.         ReleaseResource(hconfig);
  136.         return(-1);
  137.     }
  138.     if (confp->version_number > CURVERSION) {
  139.          error("Application predates the configuration version");
  140.     }
  141.     if (confp->version_number >= VERS1) {
  142.         emdp->keypad = confp->keypad;
  143.         if (confp->version_number == VERS1) {
  144.             /* translate old keyboard values */
  145.             emdp->keypad -= VERS1KEYPAD;
  146.         }
  147. #ifndef ENVIRONS
  148.         keyboard = confp->keyboard;
  149.         if (confp->version_number == VERS1) {
  150.             /* translate old keyboard values */
  151.             keyboard -= VERS1KEYBOARD;
  152.         }
  153. #endif
  154.         emdp->dokeymacros = confp->dokeymacros;
  155.         emdp->ibm_keymode = confp->ibm_mode;
  156.         emdp->changecurs = confp->changecurs;
  157.         emdp->blockcurs = confp->blockcurs;
  158.         emdp->escmap = confp->escmap;
  159.         emdp->ba_bs = confp->ba_bs;
  160.         emdp->crtonl = confp->crtonl;
  161.         emdp->typeahead = confp->typeahead;
  162.     }
  163.     if (confp->version_number >= VERS2) {
  164.         emdp->nullsareblanks = confp->ibmnulls;
  165.         emdp->squeezeblanks = confp->ibmsqueeze;
  166.         emdp->curseekmode = confp->curseekmode;
  167.  
  168.         wrap_around = emdp->wrap_around = confp->termwrap;
  169.         
  170.             /* 
  171.         emdp->ucb.u_tftp = confp->tftpserve;
  172.         emdp->ucb.u_ask = confp->tftpask;
  173.             TODO global mess tftpserve, tftpask */
  174.     }
  175.     if (confp->version_number >= VERS3) {
  176.         emdp->autoshrink = confp->autoshrink;
  177.     }
  178.     if (confp->version_number >= VERS4) {
  179.         emdp->shiftfield = confp->shiftfield;
  180.     }
  181.     if (confp->version_number >= VERS5) {
  182.         int index;
  183.         
  184.         /* make sure at least one terminal is enabled */
  185.         for (index = 0; confp->disableterm[index] && index < TERMTYPECOUNT; index++)
  186.             ;
  187.         if (index >= TERMTYPECOUNT) {
  188.             /* no terminals are enabled, surely a mistake of some sort! */
  189.             error("Ignoring config error:  all terminal types disabled");
  190.         }
  191.         else {
  192.             int firstable;
  193.             
  194.             firstable = FALSE;
  195.             for (index = 0; index < TERMTYPECOUNT; index++) {
  196.                 emdp->disableterm[index] = confp->disableterm[index];
  197.  
  198.                 if (confp->disableterm[index] || firstable)
  199.                     continue;
  200.                 
  201.                 /* set the terminal by default to the first enabled one */
  202.                 emdp->termtype = index;
  203.                 firstable = TRUE;
  204.             }
  205.         }
  206.     }
  207.     if (confp->version_number >= VERS6) {
  208.         if (environs.hasColorQD)
  209.             /* only allow color to be set if Color QuickDraw is present! */
  210.             emdp->color = confp->color;
  211.         else
  212.             emdp->color = FALSE;
  213.     }
  214.     if (confp->version_number >= VERS7) {
  215.         emdp->ibmcolormap = confp->ibmcolormap;
  216.         /* trydsdraw = confp->trydsdraw;
  217.             riskydsdraw = confp->riskydsdraw;
  218.             TODO should there be just one rather than per document? */
  219.     }
  220.     if (confp->version_number >= VERS8) {
  221.         emdp->disposeonclose = confp->disposeonclose;
  222.             
  223.         emdp->normfont = confp->normfont;
  224.         emdp->highfont = confp->highfont;
  225.         emdp->vtfont = confp->vtfont;
  226.         emdp->conntype = confp->conntype;
  227.     }
  228.     else {
  229.         emdp->normfont = 201;                /* normal font ID */
  230.         emdp->highfont = 202;                /* bold font ID */
  231.         emdp->vtfont = 74;                    /* vt100 graphics font ID */
  232.     }
  233.     if (confp->version_number >= VERS9) {
  234.         emdp->vtkeypad = confp->vtkeypad;
  235.     }
  236.     else {
  237.         emdp->vtkeypad = FALSE;
  238.     }
  239.     if (confp->version_number >= VERS10) {
  240.         emdp->logsession = confp->logsession;
  241.         emdp->filesession = confp->filesession;
  242.         emdp->editload = confp->editload;
  243.         emdp->editdownwrap = confp->editwrap;
  244.     }
  245.     else {
  246.         emdp->logsession = FALSE;
  247.         emdp->filesession = FALSE;
  248.         emdp->editload = TRUE;
  249.         emdp->editdownwrap = FALSE;
  250.     }
  251.     if (confp->version_number >= VERS11) {
  252.         emdp->autohangup = confp->autohangup;
  253.     }
  254.     else {
  255.         emdp->autohangup = FALSE;
  256.     }
  257.     if (confp->version_number >= VERS13) {
  258.         emdp->vtjumpscroll = confp->vtjumpscroll;
  259.         emdp->keypadswitch = confp->keypadswitch;
  260.         emdp->logerase = confp->logerase;
  261.         emdp->editupwrap = confp->editupwrap;
  262.  
  263.         emdp->linecount = confp->linecount;
  264.         emdp->linelength = confp->linelength;
  265.         emdp->ibm_type = confp->ibm_type;
  266.     }
  267.     else {
  268.         emdp->vtjumpscroll = FALSE;
  269.         emdp->keypadswitch = FALSE;
  270.         emdp->logerase = FALSE;
  271.         emdp->editupwrap = FALSE;
  272.  
  273.         emdp->linecount = 24;
  274.         emdp->linelength = 80;
  275.         emdp->ibm_type = IBMMOD2;
  276.     }
  277.     setcontext(emdp);                    /* update globals */
  278.  
  279.     HUnlock(hconfig);
  280.     ReleaseResource(hconfig);
  281. }
  282.  
  283.  
  284. /* release handles associated with window configuration */
  285.  
  286. releaseconfig()
  287. {
  288.     if (emdp->connmacro != NULL)
  289.         DisposHandle(emdp->connmacro);
  290.     emdp->connmacro = NULL;
  291.     
  292.     if (emdp->closemacro != NULL)
  293.         DisposHandle(emdp->closemacro);
  294.     emdp->closemacro = NULL;
  295.     
  296.     if (emdp->clickmacro != NULL)
  297.         DisposHandle(emdp->clickmacro);
  298.     emdp->clickmacro = NULL;
  299.  
  300.     if (emdp->hlasthost != NULL)
  301.         DisposHandle(emdp->hlasthost);
  302.     emdp->hlasthost = NULL;
  303.     
  304. }
  305.  
  306.  
  307.  
  308. /* set the CONF resource contents to current values of variables to be saved */
  309.  
  310. setconfig(hconf)
  311. Handle hconf;
  312. {
  313.     struct config * confp;
  314.     int index;
  315.     
  316.     confp = (struct config *) *hconf; 
  317.  
  318.     confp->version_number = CURVERSION;
  319.     confp->keyboard = keyboard;
  320.     confp->keypad = emdp->keypad;
  321.     confp->dokeymacros = emdp->dokeymacros;
  322.     confp->ibm_mode = emdp->ibm_keymode;
  323.     confp->changecurs = emdp->changecurs;
  324.     confp->blockcurs = emdp->blockcurs;
  325.     confp->escmap = emdp->escmap;
  326.     confp->ba_bs = emdp->ba_bs;
  327.     confp->crtonl = emdp->crtonl;
  328.     confp->typeahead = emdp->typeahead;
  329.     confp->ibmnulls = emdp->nullsareblanks;
  330.     confp->ibmsqueeze = emdp->squeezeblanks;
  331.     confp->curseekmode = emdp->curseekmode;
  332.     
  333.     confp->termwrap = wrap_around;
  334.     confp->tftpserve = emdp->ucb.u_tftp;
  335.     confp->tftpask = emdp->ucb.u_ask;
  336.     confp->autoshrink = emdp->autoshrink;
  337.     confp->shiftfield = emdp->shiftfield;
  338.  
  339.     for (index = 0; index < TERMTYPEMAX; index++) {
  340.         confp->disableterm[index] = emdp->disableterm[index];
  341.     }
  342.     confp->color = emdp->color;
  343.     confp->ibmcolormap = emdp->ibmcolormap;
  344.     confp->trydsdraw = trydsdraw;
  345.     confp->disposeonclose = emdp->disposeonclose;
  346.     confp->normfont = emdp->normfont;
  347.     confp->highfont = emdp->highfont;
  348.     confp->vtfont = emdp->vtfont;
  349.     confp->conntype = emdp->conntype;
  350.     
  351.     confp->vtkeypad = emdp->vtkeypad;
  352.  
  353.     confp->logsession = emdp->logsession;
  354.     confp->filesession = emdp->filesession;
  355.     confp->editload = emdp->editload;
  356.     confp->editwrap = emdp->editdownwrap;
  357.  
  358.     confp->autohangup = emdp->autohangup;
  359.  
  360.     confp->vtjumpscroll = emdp->vtjumpscroll;
  361.     confp->keypadswitch = emdp->keypadswitch;
  362.     confp->logerase = emdp->logerase;
  363.     confp->editupwrap = emdp->editupwrap;
  364.     confp->linecount = emdp->linecount;
  365.     confp->linelength = emdp->linelength;
  366.     confp->ibm_type = emdp->ibm_type;
  367.     
  368.     setlocalconfig();
  369. }
  370.  
  371.  
  372. /*    open the resource files in the file selected by the user on launching */
  373.  
  374. openlaunchres()
  375. {
  376.     short mess;
  377.     short count;
  378.     short appcount;
  379.     short refnum;
  380.     short newresfid;
  381.     WDPBRec WDPB;    
  382.     HPrmBlkRec HPB;
  383.     Str255 bvname;
  384.     char nosysconf = TRUE;
  385.     
  386.     /* we always expect a connection structure to exist */
  387.     makeconn();
  388.  
  389.     WDPB.ioCompletion = NULL;
  390.     WDPB.ioNamePtr = NULL;
  391.     PBHGetVol(&WDPB, (Boolean) FALSE);    
  392.     appresfid = CurResFile();
  393.     appvref = WDPB.ioVRefNum;
  394.     appvol = WDPB.ioWDVRefNum;    /* all vol settings from WDPBs used to use ioVRefNum */
  395.     appdir = WDPB.ioWDDirID;
  396.  
  397.     /* try to open document in blessed folder, create it if necessary;
  398.         this provides us with one file to store net configuration & host table,
  399.         as well as providing user-configurable default configuration
  400.         for new windows...
  401.     */
  402.     if (!environs.systemVersion) {
  403.         /* pre IM-V ROM, we've gotta find the "Blessed Goddam Folder" ourselves... */
  404.         bvname.length = 0; 
  405.         HPB.ioCompletion = NULL;
  406.         HPB.ioNamePtr = &bvname;
  407.         HPB.ioVRefNum = 0;
  408.         HPB.u.hvp.ioVolIndex = 1;            /* start w/ 1st vol */
  409.     
  410.         for (; ! PBHGetVInfo(&HPB, (Boolean) FALSE); HPB.u.hvp.ioVolIndex++) {
  411.             /* there's another volume to check */
  412.             
  413.             if (HPB.u.hvp.ioVFndrInfo[0]) {
  414.                 /* We found a blessed folder, let's setvol to it */
  415.                 WDPB.ioCompletion = NULL;
  416.                 WDPB.ioNamePtr = NULL;
  417.                 WDPB.ioVRefNum = HPB.ioVRefNum;
  418.                 WDPB.ioWDDirID = HPB.u.hvp.ioVFndrInfo[0];
  419.                 PBHSetVol(&WDPB, (Boolean) FALSE);
  420.                 
  421.                 WDPB.ioNamePtr = NULL;
  422.                 PBHGetVol(&WDPB, (Boolean) FALSE);
  423.                 
  424.                 environs.sysVRefNum = WDPB.ioVRefNum;
  425.                 break;
  426.             }
  427.         }
  428.     }
  429.     if (SetVol((StringPtr) NULL, environs.sysVRefNum)) {
  430.         error("Can't set volume to System Folder");
  431.     }
  432.     else {    
  433.         /* Get the vrefnum */
  434.         WDPB.ioNamePtr = NULL;
  435.         PBHGetVol(&WDPB, (Boolean) FALSE);    
  436.         setresvref = WDPB.ioVRefNum;
  437.         setresvol = WDPB.ioWDVRefNum;
  438.         setresdir = WDPB.ioWDDirID;
  439.  
  440.         if ((newresfid = myopenresfile(&setfile[0], setresvref, (Byte) fsRdWrPerm)) == -1) {
  441.             /* no config, try make a config file in the system folder */
  442.             if ((newresfid = makeconffile()) != -1) {
  443.                 /* we made the new file & set resfid, break */
  444.                 nosysconf = FALSE;
  445.             }
  446.             else {
  447.                 error("Can't create 'Comet Default' document in System Folder");
  448.             }
  449.  
  450.         }
  451.         else {
  452.             /* get configuration from the existing default file */
  453.             nosysconf = FALSE;
  454.         }
  455.     }
  456.  
  457.     if (nosysconf) {
  458.         /* no blessed folder yet, make "Comet Default" conf in launch folder */
  459.         if ((newresfid = myopenresfile(&setfile[0], appvref, (Byte) fsRdWrPerm)) == -1) {
  460.             if ((newresfid = makeconffile()) == -1) {
  461.                 /* can't even make a conf file in the app folder */
  462.                 newresfid = appresfid;
  463.             }
  464.             else {
  465.                 error("Can't create 'Comet Default' document in application folder");
  466.             }
  467.         }
  468.         else {
  469.             /* we made the new file & set resfid, break */
  470.             /* appresfid = newresfid; */
  471.             nosysconf = FALSE;
  472.         }
  473.         setresvol = appvol;
  474.         setresdir = appdir;
  475.         setresvref = appvref;
  476.     }
  477.     
  478.     getglobalconf();
  479.     setresfid = newresfid;
  480.     
  481.     fillwindclose();
  482.         /* close the copyright window if it's up */
  483.  
  484.     /* now check for document files */
  485.     CountAppFiles(&mess, &appcount);
  486.     if (appcount > 0 && mess == appOpen) {
  487.         /* the Finder wants us to open some document files */
  488.         /* open all document files, each representing one
  489.             connection with configuration data */
  490.             
  491.         closesettings();                /* close the Settings file */
  492.         
  493.         for (count = 1; appcount--; ) {
  494.             GetAppFiles(count++, &emdp->appfile);
  495.             SetVol((StringPtr) NULL, emdp->appfile.vRefNum);
  496.             if ( (newresfid = myopenresfile(&emdp->appfile.fName, emdp->appfile.vRefNum, (Byte) fsRdWrPerm) ) == -1) {
  497.                 error("Couldn't open document file");
  498.                 continue;
  499.                 /* TODO handle errors better; */
  500.             }
  501.             /* get the new vol/dir for SFPut */
  502.             WDPB.ioNamePtr = NULL;
  503.             PBHGetVol(&WDPB, (Boolean) FALSE);
  504.             emdp->resfid = newresfid;
  505.             emdp->resvref = WDPB.ioVRefNum;
  506.             emdp->resvol = WDPB.ioWDVRefNum;
  507.             emdp->resdir = WDPB.ioWDDirID;
  508.             
  509.             /* downloads default to document home */
  510.             emdp->downvref = WDPB.ioVRefNum;
  511.             emdp->downvol = WDPB.ioWDVRefNum;
  512.             emdp->downdir = WDPB.ioWDDirID;
  513.                 
  514.             getconfig();
  515.             
  516.             PtrToHand(&emdp->appfile.fName, &emdp->hhostname, 
  517.                     (long) (emdp->appfile.fName.length + 1));
  518.  
  519.             /* check to see if TCP host name is OK before making window */
  520.             if (emdp->conntype == CONN_MACTCP 
  521.                     || emdp->conntype == CONN_CUTCP) {
  522.                 /* on startup, get the null-terminated c string from the resource file */
  523.                 if (emdp->hlasthost) {
  524.                     HLock(emdp->hlasthost);
  525.                     if (resolve_name(*emdp->hlasthost, &emdp->fhost)) {
  526.                         if (namewindow()) {
  527.                             /* no address, give the user a chance to fix things */
  528.                             HUnlock(emdp->hlasthost);
  529.                             continue;
  530.                         }
  531.                     }
  532.                     HUnlock(emdp->hlasthost);
  533.                 }
  534.                 else {
  535.                     if (namewindow()) {
  536.                         /* no address, give the user a chance to fix things */
  537.                         continue;
  538.                     }
  539.                 }
  540.             }
  541.             if (makewind()) {
  542.                 /* out of memory */
  543.                 error("Not enough memory to make a window!");
  544.                 killconn();
  545.                 break;
  546.             }
  547.             keyxinit();
  548.  
  549.             windowtitle(emdp, &emdp->appfile.fName);
  550.             addwindmenu(emwindow);
  551.  
  552.             closeconfig(emdp);        /* close after getting resources */
  553.  
  554.             openconn(emdp);                /* open up the connection */
  555.             
  556.             if (appcount) {
  557.                 /* ready another connection */
  558.                 makeconn();
  559.             }
  560.         }
  561.     }
  562.     else {
  563.         /* closesettings();
  564.             TODO this would ensure Dick behavior:  not getting saved
  565.                 window position etc. from settings file */
  566.  
  567.         emdp->resfid = setresfid;
  568.         emdp->resvref = setresvref;        /* settings directory--the system folder */
  569.         emdp->resvol = setresvol;
  570.         emdp->resdir = setresdir;
  571.     
  572.         emdp->downvref = appvref;        /* download defaults into app directory */
  573.         emdp->downvol = appvol;
  574.         emdp->downdir = appdir;
  575.         
  576.         getconfig();
  577.  
  578.         /* set name to "Comet Default" */
  579.         ptoc(&setfile[0]);
  580.         strcpy(&emdp->appfile.fName, &setfile[0]);
  581.         ctop(&emdp->appfile.fName);
  582.         ctop(&setfile[0]);
  583.     
  584.         PtrToHand(&emdp->appfile.fName, &emdp->hhostname, 
  585.                 (long) (emdp->appfile.fName.length + 1));
  586.  
  587.         if (mfbackonly) {
  588.             releaseconn(emdp);
  589.         }
  590.         else {
  591.             /* do namewindow() with "Comet Default" */
  592.             
  593.             if (namewindow()) {
  594.                 /* cancelled */
  595.                 int tquit = quitonclose;
  596.                     /* don't quit if user cancels this dialog on startup! */
  597.                 
  598.                 quitonclose = FALSE;
  599.                 releaseconn(emdp);
  600.                 quitonclose = tquit;
  601.             }
  602.             else {
  603.                 if (makewind()) {
  604.                     /* out of memory */
  605.                     error("Not enough memory to make a window!");
  606.                     cu_exit(-1);
  607.                 }
  608.                 keyxinit();
  609.                 windowtitle(emdp, &emdp->appfile.fName);
  610.                 addwindmenu(emwindow);
  611.                 
  612.                 openconn(emdp);                /* open up the connection */
  613.             }
  614.             closesettings();                /* close settings now resources obtained */
  615.             emdp->resfid = 0;
  616.             
  617.         }
  618.     }
  619.     /* reset to last opened directory */
  620.     if (SetVol((StringPtr) NULL, emdp->resvref))
  621.         volerror();    
  622.     return(0);
  623. }
  624.  
  625.  
  626. /* save the current value of configuration variables in a configuration file;
  627.     user selects filename through SFPutFile.  Note that files are always 
  628.     closed except when being modified.
  629.     
  630.     this routine is always called in the emdp context... */
  631.  
  632. saveconfig(twp, creator)
  633. struct winds * twp;
  634. long creator;
  635. {
  636.     Point here;
  637.     SFReply reply;
  638.     Handle hconf;
  639.     FInfo finfo;
  640.     short curvol;                /* current volume/wd */
  641.     short newresvol;            /* new vol from SF */
  642.     long newresdir;            /* new vol from SF */
  643.     OSErr ferror;
  644.     short newfile;            /* flag to indicate new file made */
  645.     WDPBRec WDPB;    
  646.     
  647.  
  648.     here.v = 60;
  649.     here.h = 100;
  650.     centerpoint(&here);
  651.  
  652.     newfile = FALSE;
  653.     
  654.     GetVol((StringPtr) NULL, &curvol);
  655.         /* save & restore current volume for FILESAVE */
  656.     
  657.     /* fix globals so Put File appears in proper volume/directory */
  658.     *SFSaveDisk = - twp->resvol;
  659.     *CurDirStore = twp->resdir;
  660.  
  661.     emwdeactivate();
  662.     SFPutFile(pass(here), "\PSave configuration in:", 
  663.         &twp->appfile.fName, (ProcPtr) NULL, &reply);
  664.  
  665.     if (reply.good) {
  666.         short newresfid;
  667.  
  668.         if (EqualString(&reply.fName[0], &setfile[0])) {
  669.             /* a problem:  PMSP will *probably* find existing "CU3270 settings" file &
  670.                 open IT instead of file the user wants, so we ask him/her/it */
  671.             if (! updatesetdlog()) {
  672.                 return(-1);
  673.             }
  674.             reply.vRefNum = *BootDrive;
  675.                 /* guarantee this happens by resetting to boot vol */
  676.         }
  677.         /* set volume */
  678.         ferror = SetVol((StringPtr) NULL, reply.vRefNum);
  679.         if ( (newresfid = myopenresfile(&reply.fName, reply.vRefNum, (Byte) fsRdWrPerm)) == NEG) {
  680.             /* we need to make a new resource file */
  681.             
  682.             newfile = TRUE;
  683.             
  684.             CreateResFile(&reply.fName);
  685.             if (ferror = ResError()) {
  686.                 error("Can't Create document");
  687.                 SetVol((StringPtr) NULL, curvol);
  688.                 return(-1);
  689.             }
  690.             if ( (newresfid = myopenresfile(&reply.fName, reply.vRefNum, (Byte) fsRdWrPerm)) == NEG) {
  691.                 /* attempt to open new file failed */
  692.                 error("Can't Open document");
  693.                 SetVol((StringPtr) NULL, curvol);
  694.                 return(-1);
  695.             }
  696.             /* copy existing key macros into new document
  697.                 copymacros();    
  698.             */
  699.     
  700.             /* copy resources:  window & font size */
  701.          
  702.             reopenconfig(twp);        /* open the old config file */
  703.             
  704.             copyresource('WIND', 0, twp->resfid, newresfid);
  705.             copyresource('WIND', 1, twp->resfid, newresfid);
  706.             copyresource('WIND', 2, twp->resfid, newresfid);
  707.             copyresource('Fsiz', 0, twp->resfid, newresfid);
  708.             copyresource('CONF', CONFID, twp->resfid, newresfid);
  709.             copyresource('CONF', SERCONFID, twp->resfid, newresfid);
  710.             copyresource('CONN', 0, twp->resfid, newresfid);
  711.             
  712.             UseResFile(newresfid);
  713.  
  714.             closeconfig(twp);
  715.                 /* close the old config file */
  716.  
  717.             /* fix the file type and creator so finder will do launches */
  718.             GetFInfo(&reply.fName, reply.vRefNum, &finfo);
  719.             finfo.fdType = 'TEXT';
  720.             finfo.fdCreator = creator;
  721.             SetFInfo(&reply.fName, reply.vRefNum, &finfo);
  722.         }
  723.         /* NOW we make the new file the default resource file for this window */
  724.         twp->resfid = newresfid;
  725.  
  726.         SetVol((StringPtr) NULL, reply.vRefNum);
  727.         twp->resvref = reply.vRefNum;
  728.         twp->resvol = -(*SFSaveDisk); 
  729.         twp->resdir = *CurDirStore;
  730.  
  731.         twp->downvref = reply.vRefNum;
  732.         twp->downvol = twp->resvol;
  733.         twp->downdir = twp->resdir;
  734.             /* save for the next SFget dialog */
  735.  
  736.         /* update the name for the next Save */
  737.         ptoc(&reply.fName[0]);
  738.         ptoc(&twp->appfile.fName);
  739.         strcpy(&twp->appfile.fName, &reply.fName[0]);
  740.         ctop(&reply.fName[0]);
  741.         ctop(&twp->appfile.fName);
  742.  
  743.         /* save the resources */
  744.         if ( (hconf = Get1Resource('CONF', CONFID)) == (Handle) NULL ) {
  745.             /* we need to make a resource... */    
  746.             hconf = NewHandle((long) sizeof (struct config));
  747.             if (hconf == (Handle) NULL) {
  748.                 error("Not enough memory to perform command");
  749.                 SetVol((StringPtr) NULL, curvol);
  750.                 closeconfig(twp);
  751.                 return(-1);
  752.             }
  753.             AddResource(hconf, 'CONF', (short) CONFID, "\P");
  754.             if (ResError()) {
  755.                 error("Can't Create 'CONF' resource");
  756.                 SetVol((StringPtr) NULL, curvol);
  757.                 closeconfig(twp);
  758.                 return(-1);
  759.             }
  760.         }
  761.         SetHandleSize(hconf, (Size) (sizeof (struct config)));
  762.             /* make sure it's large enough */
  763.         setconfig(hconf);
  764.  
  765.         if (saveresource(twp->resfid, twp->resvol, hconf)) {
  766.             error("Can't Save document resource");
  767.             SetVol((StringPtr) NULL, curvol);
  768.             closeconfig(twp);
  769.             return(-1);
  770.         }
  771.         ReleaseResource(hconf);
  772.  
  773.         savehostres(twp);
  774.             /* save the hlasthost IP address resource */
  775.  
  776.         FlushVol((StringPtr) NULL, 0);
  777.         
  778.         SetVol((StringPtr) NULL, curvol);
  779.  
  780.         closeconfig(twp);
  781.             /* close the new file */
  782.             
  783.         /* update the hostname */
  784.         if (twp->hhostname) {
  785.             DisposHandle(twp->hhostname);
  786.             twp->hhostname = NULL;
  787.         }
  788.         PtrToHand(&twp->appfile.fName, &twp->hhostname, 
  789.                 (long) (twp->appfile.fName.length + 1));
  790.  
  791.         if (twp->emwindow) {
  792.             windowtitle(twp, &twp->appfile.fName);
  793.             windmenutitle(twp);
  794.         }
  795.         
  796.         twp->confchanged = FALSE;
  797.         twp->newconf = FALSE;
  798.         
  799.         return(0);
  800.     }
  801.     /* previous vol/dir maintained */
  802.     closeconfig(twp);
  803.     return(-1);
  804. }
  805.  
  806.  
  807. /* copy a resource from one file to another; 
  808.     rsrc file order left as: current, dst, src */
  809.  
  810. copyresource(restype, resnum, srcfid, dstfid)
  811. long restype;
  812. int resnum;
  813. short srcfid;
  814. short dstfid;
  815. {
  816.     short saveresfid;
  817.     Handle reshand;
  818.     short junkid;
  819.     long junktype;
  820.     Str255 resname;
  821.     
  822.     saveresfid = CurResFile();
  823.     
  824.     /* get the resource & its name */
  825.     UseResFile(srcfid);
  826.     reshand = Get1Resource(restype, (short) resnum);
  827.     if (reshand == NULL) {
  828.         UseResFile(saveresfid);
  829.         return(-1);
  830.     }
  831.     GetResInfo(reshand, &junkid, &junktype, &resname);
  832.     
  833.     /* detach, switch files, and save it */
  834.     DetachResource(reshand);
  835.     UseResFile(dstfid);
  836.     AddResource(reshand, restype, (short) resnum, &resname);
  837.     UpdateResFile(dstfid); 
  838.     ReleaseResource(reshand);
  839.     
  840.     UseResFile(saveresfid);
  841. }
  842.  
  843.  
  844. /* try to make a configuration file, return newresfid */
  845.  
  846. makeconffile()
  847. {
  848.     Handle hconf;
  849.     FInfo finfo;
  850.     short newresfid;
  851.  
  852.     copynotice();        /* remove for Stuart! but present the first time... */
  853.  
  854.     CreateResFile(&setfile[0]);
  855.     if (ResError()) {
  856.         return(-1);
  857.     }
  858.     newresfid = myopenresfile(&setfile[0], setresvref, (Byte) fsRdWrPerm);
  859.     if (newresfid == -1) {
  860.         newresfid = ResError();
  861.         error(strsetcantopen);
  862.         return(-1);
  863.     }
  864.  
  865.     /* set FInfo so it can launch if desired */
  866.     GetFInfo(&setfile[0], 0, &finfo);
  867.     finfo.fdType = 'TEXT';
  868.     finfo.fdCreator = creator;
  869.     SetFInfo(&setfile[0], 0, &finfo);
  870.  
  871.     /* now copy defaults into conf file */
  872.     getconfig();                /* set some defaults first */
  873.     if ( (hconf = modresource(emdp, 'CONF', CONFID, sizeof(struct config)))
  874.             == (Handle) NULL ) {
  875.         return(-1);
  876.     }
  877.     setconfig(hconf);
  878.     
  879.     if (saveresource(newresfid, emdp->resvol, hconf)) {
  880.         error("Can't save configuration resource");
  881.         return(-1);
  882.     }
  883.     ReleaseResource(hconf);
  884.     
  885.     /* copy other user-modifiable resources */
  886.     /* copyresource('CONF', GLOBCONFID, appresfid, newresfid); */
  887.     copyresource('CUSS', 0, appresfid, newresfid);
  888.     copyresource('CUSS', 1, appresfid, newresfid);
  889.     copyresource('DEFG', 0, appresfid, newresfid);
  890.     copyresource('DEFG', 1, appresfid, newresfid);
  891.     copyresource('NETD', 0, appresfid, newresfid);
  892.     copyresource('TMZO', 0, appresfid, newresfid);
  893.  
  894.     /* copyresource('LHST', 0, appresfid, newresfid);    obsolete */
  895.  
  896.     copyresource('Fsiz', 0, appresfid, newresfid);
  897.     copyresource('WIND', 0, appresfid, newresfid);
  898.     copyresource('WIND', 1, appresfid, newresfid);
  899.     copyresource('WIND', 2, appresfid, newresfid);
  900.  
  901.     FlushVol((StringPtr) NULL, 0);
  902.     
  903.     UseResFile(newresfid);
  904.     return(newresfid);
  905. }
  906.  
  907. /* query to user to determine whether he wishes to update the CU3270 settings 
  908.     file in the system folder, return FALSE if not */
  909.     
  910. #define SETD_OK        1
  911. #define SETD_CANCEL    2
  912.  
  913. updatesetdlog()
  914. {
  915.     DialogPtr    setdial;
  916.     short    item_id;
  917.     short    type;
  918.     Rect rect;
  919.     Handle hitem;
  920.         /* general purpose GetDItem vars */
  921.     GrafPtr    oport;
  922.  
  923.     GetPort(&oport);
  924.  
  925.     emwdeactivate();
  926.     if ((setdial = GetNewDialog(DSETTINGS, (Ptr) NULL, (WindowPtr) (-1))) == NULL)
  927.         return(-1);
  928.  
  929.     centerwind(setdial);
  930.  
  931.     SetCursor(&arrow);
  932.     SetPort(setdial);
  933.     modaldialog = TRUE;
  934.  
  935.     GetDItem(setdial, SETD_OK, &type, &hitem, &rect);
  936.     buthilite(&rect);
  937.         /* hilite "OK" key */
  938.  
  939.     while (TRUE) {
  940.         ModalDialog((ProcPtr) alfilter, &item_id);
  941.         switch (item_id) {
  942.             case SETD_CANCEL: {
  943.                 SetPort(oport);
  944.                 DisposDialog(setdial);
  945.                 modaldialog = FALSE;
  946.                 return(0);
  947.             }
  948.             case SETD_OK: {
  949.                 SetPort(oport);
  950.                 DisposDialog(setdial);
  951.                 modaldialog = FALSE;
  952.                 return(TRUE);
  953.             }
  954.             default: {
  955.                 break;
  956.             }
  957.         }
  958.     }
  959. }
  960.  
  961.  
  962.  
  963. /* return a Handle to a fresh resource; kill the old one if necessary */
  964.  
  965. Handle
  966. modresource(twp, restype, resnum, size)
  967. struct winds * twp;
  968. long restype;
  969. int resnum;
  970. unsigned int size;
  971. {
  972.     Handle hconf;
  973.  
  974.     if ( (hconf = Get1Resource(restype, (short) resnum)) != NULL) {
  975.         /* a resource is already in the current resource file, so kill it */
  976.         RmveResource(hconf);
  977.         if (ResError()) {
  978.             error("Can't Delete resource");
  979.         }
  980.         UpdateResFile(twp->resfid);
  981.         DisposHandle(hconf);
  982.     }
  983.     /* add new resource */
  984.     hconf = NewHandle((long) size);
  985.     if (hconf == (Handle) NULL)
  986.         return((Handle) NULL);
  987.     AddResource(hconf, restype, (short) resnum, "\P");
  988.     if (ResError()) {
  989.         return((Handle) NULL);
  990.     }
  991.     return(hconf);
  992. }
  993.  
  994.  
  995. /* save the resource with handle hconf in the current resource file */
  996. /* TODO does FlushVol() require real vol as we are using? */
  997.  
  998. saveresource(resfid, resvol, hconf)
  999. short resfid;
  1000. short resvol;
  1001. Handle hconf;
  1002. {
  1003.     ChangedResource(hconf);
  1004.     if (ResError()) {
  1005.         return(-1);
  1006.     }
  1007.     UpdateResFile(resfid); 
  1008.     if (ResError()) {
  1009.         return(-1);
  1010.     }
  1011.     FlushVol((StringPtr) NULL, (short) resvol);    /* flush the volume */
  1012.     return(0);
  1013. }
  1014.  
  1015.  
  1016. /* set some unavoidable historical defaults */
  1017.  
  1018. defaultconf()
  1019. {
  1020.     emdp->escmap = TRUE;
  1021.     emdp->ucb.u_tftp = TFNO;
  1022.     emdp->ucb.u_ask = TRUE;
  1023.  
  1024.     emdp->normfont = 201;                /* normal font ID */
  1025.     emdp->highfont = 202;                /* bold font ID */
  1026.     emdp->vtfont = 74;                    /* vt100 graphics font ID */
  1027.  
  1028.     emdp->changecurs = TRUE;            /* make cursor blink */
  1029.     wrap_around = emdp->wrap_around = TRUE;            /* wrap at end of line if true */
  1030.     
  1031.     emdp->keypad = KEYPAD3;                /* ibm emdp->keypad mode */
  1032.     emdp->typeahead = TRUE;                /* ibm do typeahead */
  1033.     emdp->nullsareblanks = TRUE;        /* causes imbedded nulls to be sent as blanks */
  1034.     emdp->squeezeblanks = TRUE;            /* squeeze blanks and not just nulls on insert */
  1035.  
  1036.     emdp->ibmcolormap = asccolormap;
  1037.         
  1038.     emdp->vtkeypad = FALSE;                /* let host set keypad */
  1039.     
  1040.     emdp->logsession = FALSE;            /* dont' log session */
  1041.     emdp->filesession = FALSE;            /* dont' log session */
  1042.  
  1043.     emdp->editload = TRUE;                /* automatically load file ~.edit into .edit */
  1044.     emdp->editupwrap = FALSE;            /* DONT automatically wrap text */
  1045.     emdp->editdownwrap = FALSE;            /* DONT automatically wrap text */
  1046.     
  1047.     emdp->autohangup = FALSE;            /* automatically hangup serial port on close */
  1048.  
  1049.     emdp->vtjumpscroll = FALSE;
  1050.     emdp->keypadswitch = FALSE;
  1051.     emdp->logerase = FALSE;
  1052.     emdp->editupwrap = FALSE;
  1053.     emdp->linecount = 24;
  1054.     emdp->linelength = 80;
  1055.     emdp->ibm_type = IBMMOD2;            /* 3278-2 (model 2) by default */
  1056.  
  1057.     setcontext(emdp);                    /* update globals */
  1058.     localconfig();
  1059.         /* this routine must be present in the application to handle less 
  1060.             general parameters such as serial port stuff */
  1061. }
  1062.  
  1063.  
  1064. /* open a document file */
  1065.  
  1066. reopenconfig(thedp)
  1067. struct winds * thedp;    
  1068. {
  1069.     WDPBRec WDPB;
  1070.     char errtext[200];
  1071.     extern short setresfid;
  1072.     
  1073.     if (thedp->resfid) {
  1074.         return(0);    
  1075.     }
  1076.         
  1077.     WDPB.ioCompletion = NULL;
  1078.     WDPB.ioNamePtr = NULL;
  1079.     
  1080.     if (thedp->newconf) {
  1081.         if (opensettings()) {
  1082.             /* no config, default to the application */
  1083.             
  1084.             thedp->resfid = appresfid;
  1085.             thedp->resvref = appvref;
  1086.             thedp->resvol = appvol;
  1087.             thedp->resdir = appdir;
  1088.  
  1089.             return(-1);
  1090.         }
  1091.         else {
  1092.             /* we have opened the settings file, identify this file with it */
  1093.             
  1094.             thedp->resfid = setresfid;
  1095.             thedp->resvref = setresvref;
  1096.                 /* TODO is this the folder we want it in ? */
  1097.         }
  1098.     }
  1099.     else {
  1100.         if (SetVol((StringPtr) NULL, thedp->resvref))
  1101.             volerror();
  1102.         if ((thedp->resfid = myopenresfile(&thedp->appfile.fName, thedp->resvref, (Byte) fsRdWrPerm)) == -1) {
  1103.             /* no config, default to the application */
  1104.             thedp->resfid = appresfid;
  1105.             thedp->resvref = appvref;
  1106.             thedp->resvol = appvol;
  1107.             thedp->resdir = appdir;
  1108.  
  1109.             return(-1);
  1110.         }
  1111.     }
  1112.     return(0);    
  1113. }
  1114.  
  1115.  
  1116.  
  1117. closeconfig(twp)
  1118. struct winds * twp;
  1119. {
  1120.     if (twp->resfid == 0)
  1121.         /*  it's not open */
  1122.         return(0);
  1123.  
  1124.     if (twp->resfid == appresfid) {
  1125.         /*  we're using the CU3270 settings resource file, leave it open */
  1126.         twp->resfid = 0;
  1127.         return(0);
  1128.     }
  1129.  
  1130.     if (twp->resfid == setresfid)
  1131.         /* if it happens to be the settings file, make sure global is reset */
  1132.         setresfid = 0;
  1133.         
  1134.     CloseResFile(twp->resfid);
  1135.     twp->resfid = 0;
  1136. }
  1137.  
  1138.  
  1139. /* reset the directory to the home directory for this window's document */
  1140.  
  1141. mac_setconfvol()
  1142. {
  1143.     if (SetVol((StringPtr) NULL, emdp->resvref))
  1144.         volerror();
  1145.  
  1146. }
  1147.  
  1148.  
  1149. /* reset the directory to this session's download directory */
  1150.  
  1151. mac_setdownvol()
  1152. {
  1153.     if (SetVol((StringPtr) NULL, emdp->downvref))
  1154.         volerror();
  1155.  
  1156. }
  1157.  
  1158.  
  1159. getglobalconf()
  1160. {
  1161.     Handle hglobal;
  1162.     struct globalconfig * confp;
  1163.     int version;
  1164.  
  1165.         /* TODO save name ? */
  1166.     if ((hglobal = GetResource('CONF', GLOBCONFID)) != NULL) {
  1167.         HLock(hglobal);
  1168.         confp = (struct globalconfig *) *hglobal; 
  1169.     
  1170.         tftpserve = confp->tftpserve;
  1171.         tftpask = confp->tftpask;
  1172.         trydsdraw = confp->trydsdraw;
  1173.         riskydsdraw = confp->riskydsdraw;
  1174.         quitonclose = confp->quitonclose;
  1175.         
  1176.         if (GetHandleSize(hglobal) > 10) {
  1177.             /* kluge because version # foolishly not included in original struct */
  1178.             version = confp->version;
  1179.         }
  1180.         else {
  1181.             version = 0;
  1182.         }
  1183.         if (version >= 1) {
  1184.             mtcpsendasync = confp->mtcpsendasync;
  1185.         }
  1186.         else {
  1187.             mtcpsendasync = FALSE;
  1188.         }
  1189.         if (version >= 2) {
  1190.             edresetselect = confp->edresetselect;
  1191.         }
  1192.         else {
  1193.             edresetselect = TRUE;
  1194.         }
  1195.         if (version >= 3) {
  1196.             keypadswitch = confp->keypadswitch;
  1197.         }
  1198.         else {
  1199.             keypadswitch = FALSE;
  1200.         }
  1201.         if (version >= 4) {
  1202.             courierprint = confp->courierprint;
  1203.         }
  1204.         else {
  1205.             courierprint = FALSE;
  1206.         }
  1207.         HUnlock(hglobal);
  1208.         ReleaseResource(hglobal);
  1209.     }
  1210.     else {
  1211.         /* stock configuration */
  1212.         tftpserve = TFNO;
  1213.         tftpask = TFYES;
  1214.         trydsdraw = FALSE;
  1215.         riskydsdraw = FALSE;
  1216.         quitonclose = FALSE;
  1217.         mtcpsendasync = FALSE;
  1218.         edresetselect = TRUE;
  1219.         keypadswitch = FALSE;
  1220.         courierprint = FALSE;
  1221.     }
  1222. }
  1223.  
  1224.  
  1225. /* open the "Comet Settings" file */
  1226.  
  1227. opensettings()
  1228. {
  1229.     if (setresfid)
  1230.         return(0);
  1231.         
  1232.     if (SetVol((StringPtr) NULL, setresvref))
  1233.         error("Can't set volume to Default");
  1234.  
  1235.     if ((setresfid = myopenresfile(&setfile[0], setresvref, (Byte) fsRdWrPerm)) == -1) {
  1236.         /* can't reopen Settings file, give up */
  1237.         error(strsetcantopen);
  1238.         setresfid = 0;
  1239.         return(-1);
  1240.     }
  1241.     return(0);
  1242. }
  1243.  
  1244.  
  1245. /* close the "Comet Settings" file */
  1246.  
  1247. closesettings()
  1248. {
  1249.     if (setresfid)
  1250.         CloseResFile(setresfid);
  1251.     setresfid = 0;
  1252. }
  1253.  
  1254.  
  1255. /* save important global vars in CONF resource in settings file */
  1256.  
  1257. saveglobalconfig()
  1258. {
  1259.     Handle hglobal;
  1260.     struct globalconfig * confp;
  1261.     
  1262.     if (opensettings())
  1263.         return(-1);
  1264.         
  1265.     if ((hglobal = GetResource('CONF', GLOBCONFID)) == NULL) {
  1266.         /* we need to make a resource... */    
  1267.         hglobal = NewHandle((long) sizeof (struct globalconfig));
  1268.         if (hglobal == (Handle) NULL) {
  1269.             return(-1);
  1270.         }
  1271.         AddResource(hglobal, 'CONF', (short) GLOBCONFID, "\P");
  1272.         if (ResError()) {
  1273.             return(-1);
  1274.         }
  1275.     }
  1276.     SetHandleSize(hglobal, (Size) (sizeof (struct globalconfig)));
  1277.         /* make sure it's large enough */
  1278.  
  1279.     HLock(hglobal);
  1280.     confp = (struct globalconfig *) *hglobal; 
  1281.  
  1282.     confp->tftpserve = tftpserve;
  1283.     confp->tftpask = tftpask;
  1284.     confp->trydsdraw = trydsdraw;
  1285.     confp->riskydsdraw = riskydsdraw;
  1286.     confp->quitonclose = quitonclose;
  1287.     confp->version = GLOBVERSION;
  1288.     confp->mtcpsendasync = mtcpsendasync;
  1289.     confp->edresetselect = edresetselect;
  1290.     confp->keypadswitch = keypadswitch;
  1291.     confp->courierprint = courierprint;
  1292.  
  1293.     HUnlock(hglobal);
  1294.     saveresource(setresfid, setresvol, hglobal);
  1295.     ReleaseResource(hglobal);
  1296.     
  1297.     closesettings();
  1298.     return(0);
  1299. }
  1300.  
  1301.  
  1302. volerror()
  1303. {
  1304.     error(strbadvol);
  1305.     SetVol((StringPtr) NULL, appvol);
  1306. }
  1307.  
  1308.  
  1309.  
  1310. myopenresfile(fName, resvref)
  1311. Str255 * fName;
  1312. short resvref;
  1313. {
  1314.     short resfid;
  1315.     short reserror;
  1316.     char errtext[200];
  1317.     
  1318.     SetVol((StringPtr) NULL, resvref);
  1319.     
  1320.      if (environs.systemVersion)
  1321.         resfid = OpenRFPerm(fName, resvref, (Byte) fsRdWrPerm);
  1322.     else 
  1323.         resfid = OpenResFile(fName);
  1324.  
  1325.     return(resfid);
  1326. }
  1327.  
  1328. /* set the default directories for a new window */
  1329.  
  1330. setwindvols(twp)
  1331. struct winds * twp;
  1332. {
  1333.     twp->resvref = setresvref;        /* settings directory--the system folder */
  1334.     twp->resvol = appvol;             /* new settings default into app directory */
  1335.     twp->resdir = appdir;
  1336.  
  1337.     twp->downvref = appvref;        /* download defaults into app directory */
  1338.     twp->downvol = appvol;
  1339.     twp->downdir = appdir;
  1340. }
  1341.  
  1342.  
  1343. /* set the resource vref, vol, & dir to the current directory */
  1344.  
  1345. setemdpresvol()
  1346. {
  1347.     WDPBRec WDPB;
  1348.         
  1349.     WDPB.ioCompletion = NULL;
  1350.     WDPB.ioNamePtr = NULL;
  1351.  
  1352.     PBHGetVol(&WDPB, (Boolean) FALSE);
  1353.     emdp->resvref = WDPB.ioVRefNum;
  1354.     emdp->resvol = WDPB.ioWDVRefNum;
  1355.     emdp->resdir = WDPB.ioWDDirID;
  1356.  
  1357.     emdp->downvref = WDPB.ioVRefNum;
  1358.     emdp->downvol = WDPB.ioWDVRefNum;
  1359.     emdp->downdir = WDPB.ioWDDirID;
  1360. }
  1361.  
  1362.